package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * ClassName: SysRoleController
 * Package: com.atguigu.spzx.manager.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/1 16:25
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {
    @Resource
    private SysRoleService sysRoleService;

    /**
     * 查询所有角色
     * @return
     */
    @GetMapping("findAllRoles/{userId}")
    public Result findAllRoles(@PathVariable Long userId){
        Map<String, Object> map =  sysRoleService.findAllRoles(userId);
        return Result.build(map,ResultCodeEnum.SUCCESS);
    }
    /**
     * 根据id删除角色
     */
    @DeleteMapping("deleteSysRoleById/{id}")
    public Result deleteSysRoleById(@PathVariable Long id){
        sysRoleService.deleteSysRoleById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改系统角色
     * @param sysRole
     * @return
     */
    @PutMapping("updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole){
        sysRoleService.updateSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加系统角色
     * @param sysRole
     * @return
     */

    @PostMapping("saveSysRole")
    public Result saveSysRole(@RequestBody SysRole sysRole){
        sysRoleService.saveSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 分页带条件模糊查询
     * @return
     */
    @GetMapping("findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> findByPage(SysRoleDto sysRoleDto,
                                                @PathVariable Integer pageNum,
                                                @PathVariable Integer pageSize){
        PageInfo<SysRole> page = sysRoleService.findByPage(sysRoleDto,pageNum,pageSize);
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }
}
